/*
 * Copyright (c) 2022. All rights reserved.
 * Please don't try to modify the code, because I don't know what the consequences will be.
 *
 *
 *
 *
 *
 *
 *
 */

package cc.zzone.bean;

import java.io.Serial;
import java.io.Serializable;

/**
 * 统一返回格式类
 *
 * @author jinzhengze
 * @since 2023年5月18日
 */
public record Result<T>(Integer code, String msg, T data) implements Serializable {

    @Serial
    private static final long serialVersionUID = 22L;
    public static final int OK = 1;
    public static final int FAIL = -1;

    public static <T> Result<T> success(T data) {
        return response(OK, "OK", data);
    }

    public static <T> Result<T> fail(String msg) {
        return response(FAIL, msg, null);
    }

    public static <T> Result<T> response(Integer code, String msg, T data) {
        return new Result<>(code, msg, data);
    }
}
